package www.wen.com.common.lib.helper.loading

import android.app.Activity
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import com.dylanc.loadinghelper.LoadingHelper
import com.gyf.immersionbar.ImmersionBar
import www.wen.com.common.R
import www.wen.com.common.lib.app.BaseApplication

/**
 * @author WEN
 * @Description: 不需要标题栏，但可能需要状态的Adapter，例如空数据状态、加载状态、错误状态
 * @date 2020/12/8 15:27
 */
class NoTitleAdapter(
        private var activity: Context,
        private var isSetTitleBarHeight: Boolean = false, //设置状态栏高度
        private var background:Int = ContextCompat.getColor(BaseApplication.CONTEXT, R.color.color0F0F11),
) : LoadingHelper.Adapter<NoTitleAdapter.ViewHolder>() {

    lateinit var mViewHolder: ViewHolder

    override fun onBindViewHolder(holder: ViewHolder) {
        holder.placeholderView.setBackgroundColor(background)

        if(isSetTitleBarHeight){
            ImmersionBar.setTitleBar(activity as Activity, holder.placeholderView)
        }
    }

    override fun onCreateViewHolder(inflater: LayoutInflater, parent: ViewGroup): ViewHolder {
        return ViewHolder(inflater.inflate(R.layout.layout_no_title, parent, false))
    }

    class ViewHolder(val view: View) : LoadingHelper.ViewHolder(view) {
        var placeholderView: View = view.findViewById(R.id.placeholderView)
    }

}